package net.alche.fa.core.doing;
import net.alche.fa.core.model.Logic;
import net.alche.fa.core.model.FaValue;
import net.alche.fa.core.CodeLevel;
import net.alche.fa.core.SageStone;
import net.alche.fa.core.FaException;

//
// three
//
@FaAnnoDoing
public class TernaryDo extends AbstractDoing {

  @Override
  public boolean matched(String what, Logic g) {
    return what != null && what.equals("?");
  }

  @Override
  public FaValue doing(Logic g, CodeLevel lvl, SageStone st) throws FaException {
    // Logic ifPart = g.getLogicObj()
    FaValue ifValue = super.getLogicObjVal(st, lvl, g);
    Logic dataPart = g.getLogicData();
    if (ifValue.getBoolValue()) {
      return super.getLogicObjVal(st, lvl, dataPart);
    }
    else {
      return super.getLogicDataVal(st, lvl, dataPart);
    }
  }
}